import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from "axios";
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// 注册ElementUI
Vue.use(ElementUI)
// 全局配置axios
Vue.prototype.$axios = axios

Vue.config.productionTip = false
/*axios.defaults.baseURL = 'http://127.0.0.1:10001'*/

//配置axios的请求拦截，设置请求头，设置token
axios.interceptors.request.use(config => {
    // console.log("store",store)
    // console.log("store.state",store.state)
    //console.log("store.state.token",store.state.token)
    const  isloginRequest = config.url && config.url.includes("http://localhost:10001/user/login")
    if(!isloginRequest && store.state.token){
        //token不为空，请求之前给每个请求头设置token
        config.headers['Authorization'] = store.state.token;
    }
    return config;
},function (error) {
    //响应请求错误
    return Promise.reject(error);
})



new Vue({
    router,
    store,
    render: function (h) {
        return h(App)
    }
}).$mount('#app')
